package hn.cch.reactive.configuration;

import hn.cch.reactive.handler.TestHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

@Configuration
public class RouteConfiguration {

    @Bean
    public RouterFunction<ServerResponse> newTestHandler(TestHandler testHandler) {
        return RouterFunctions.route()
            .GET("/json", RequestPredicates.accept(MediaType.APPLICATION_JSON), testHandler::json)
            .GET("/text", RequestPredicates.accept(MediaType.TEXT_PLAIN), testHandler::text)
            .build();
    }
}
